home *** CD-ROM | disk | FTP | other *** search
- /* initialize, open, etc. various things for brwsr program...
- * 870805-13... ^z
- */
-
- #include <stdio.h> /* for FILE, getc(), etc. */
- #include <strings.h> /* for strcpy(), strcat(), etc. */
- #include <unix.h> /* for exit(), time(), etc. */
- #include <proto.h> /* for function prototypes */
- #include "brwsr.h" /* for various definitions */
- #include "brwsr.proto.h" /* for my function prototypes */
-
-
- /* open the document, key, and pointer files ...
- * for now, demand that if the document file is named * then the
- * key file must be named *.k and the pointer file must be *.p
- * ... just the way that the ndxr program builds the index.....
- */
-
- void open_files (cmd)
- char cmd[];
- {
- char ocmd[STRLEN], *strcat(), *strcpy();
- FILE *fopen();
- extern FILE *doc_file, *key_file, *ptr_file;
-
- close_files ();
- strcpy (ocmd, cmd + 1);
- if ((doc_file = fopen (ocmd, "r")) == NULL)
- {
- beep ();
- printf ("Error opening document file \"%s\"!\n", ocmd);
- close_files ();
- return;
- }
-
- strcat (ocmd, ".k");
- if ((key_file = fopen (ocmd, "rb")) == NULL)
- {
- beep ();
- printf ("Error opening key file \"%s\"!\n", ocmd);
- close_files ();
- return;
- }
-
- ocmd[strlen (ocmd) - 2] = '\0';
- strcat (ocmd, ".p");
- if ((ptr_file = fopen (ocmd, "rb")) == NULL)
- {
- beep ();
- printf ("Error opening ptr file \"%s\"!\n", ocmd);
- close_files ();
- return;
- }
- }
-
-
- /* close off the document, key, and pointer files
- */
-
- void close_files ()
- {
- extern FILE *doc_file, *key_file, *ptr_file;
-
- if (doc_file != NULL)
- {
- fclose (doc_file);
- doc_file = NULL;
- }
- if (key_file != NULL)
- {
- fclose (key_file);
- key_file = NULL;
- }
- if (ptr_file != NULL)
- {
- fclose (ptr_file);
- ptr_file = NULL;
- }
- }
-
-
- /* set up initial values for current_item and max_item arrays ...
- * initially, current_item is set to an illegal value, -1, and
- * max_item[CONTEXT] and max_item[TEXT] convey information about
- * the sizes of the pointer and document files respectively...
- */
-
- void init_items ()
- {
- extern long current_item[], max_item[];
- extern FILE *doc_file, *key_file, *ptr_file;
- extern int level;
-
- level = INDEX;
-
- current_item[INDEX] = -1;
- current_item[CONTEXT] = -1;
- current_item[TEXT] = -1;
-
- fseek (key_file, 0L, 2);
- max_item[INDEX] = ftell (key_file) / sizeof (KEY_REC) - 1;
-
- fseek (ptr_file, 0L, 2);
- max_item[CONTEXT] = ftell (ptr_file) / sizeof (PTR_REC) - 1;
-
- fseek (doc_file, 0L, 2);
- max_item[TEXT] = ftell (doc_file) - 1;
- }
-
-
-